import _axios from './_axios'

import localStorage from '../../src/modules/localStorage'
// import localStorage from '../localStorage'
// const localStorage = require('../../src/modules/localStorage');

export const interceptor = (flag = false)=>{
    if(flag) return;
                // 添加请求拦截器
    _axios.interceptors.request.use(
        config => {
        
            if(localStorage.get('token')) {
                config.headers.token = localStorage.get('token');
            }
            return config;
        },
        err => Promise.reject(err)
    );

    // 添加响应拦截器

    _axios.interceptors.response.use(
        response => {
            // 在响应数据成功拦截之前走一些事情....

            return response
        },
        err => {
            if(err && err.response) {
                console.log(err.response.status);
            }
            return Promise.reject(err.response && err.response.data)
        }
    );
}

